#include "Script.h"
#include "../Framework/Exceptions.h"

Script::Script(std::ifstream inputScript)
{
	calculator calc;
	std::string str;
	while (std::getline(inputScript, str))
	{
		if (str.empty() || str[0] == 'q' || str[0] == 'Q')
			break;

		m_vectTreeParseInfo.push_back(ast_parse(str.c_str(), calc));

		if (m_vectTreeParseInfo.back().full)
		{
#if defined(BOOST_SPIRIT_DUMP_PARSETREE_AS_XML)
			// dump parse tree as XML
			std::map<parser_id, std::string> rule_names;
			rule_names[calculator::integerID] = "integer";
			rule_names[calculator::factorID] = "factor";
			rule_names[calculator::termID] = "term";
			rule_names[calculator::expressionID] = "expression";
			tree_to_xml(cout, info.trees, str.c_str(), rule_names);
#endif

		}
		else
		{
			ACError("Error during parsing of the script");
		}
	}
}